//
//  NSString+Java.m
//
//  Created by GaoShin on 2019/8/29.
//

#import "JavaString.h"

@implementation NSString (Java)

-(NSInteger) indexOf:(NSString *)str{
    NSRange range = [self rangeOfString:str];
    if(range.location==NSNotFound){
        return -1;
    } else {
        return range.location;
    }
}

-(NSInteger) lastIndexOf:(NSString *)str{
    NSRange range = [self rangeOfString:str options:NSBackwardsSearch];
    if(range.location==NSNotFound){
        return -1;
    } else {
        return range.location;
    }
}


-(NSInteger) indexOfChar:(char) cha{
    return NSNotFound;
}

-(NSInteger) lastIndexOfChar:(char) cha{
    return NSNotFound;
}

-(NSString *) substringFromIndex:(NSUInteger)from To:(NSUInteger)to{
    return [self substringWithRange: NSMakeRange(from, to-from)];
}

-(BOOL) startWith:(NSString *) prefix{
    return [self hasPrefix:prefix];
}

-(BOOL) endWith:(NSString *) suffix{
    return [self hasSuffix:suffix];
}

-(NSArray *) split:(NSString *) char1{
    NSArray * aArray = [self componentsSeparatedByString:char1];
    return aArray;
}

-(NSString *) trim{
    return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

+(NSString *) valueOf:(long long) longlongValue {
    return [NSString stringWithFormat:@"%lld",longlongValue];
}

-(NSString *) replaceOldString:(NSString *) oldStr toNewString:(NSString *) newString{
    return [self stringByReplacingOccurrencesOfString:oldStr withString:newString];
}

@end
